﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace sieuthi
{
    public partial class nhacc : Form
    {
        private SqlDataAdapter da = new SqlDataAdapter();
        private SqlConnection conn = new SqlConnection(Threelayer.VO.core.connectionsring.ToString());
        private SqlCommand cmd = new SqlCommand();
        private DataTable dt = new DataTable("nhacungcap");
        Threelayer.VO.nhacungcapVO nhacc_vo;
        Threelayer.BUS.nhacungcapBUS nhacc_bus;
        public nhacc()
        {
            InitializeComponent();
        }

        private void nhacc_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'sieuthiDataSet.nhacungcap' table. You can move, or remove it, as needed.
            this.nhacungcapTableAdapter.Fill(this.sieuthiDataSet.nhacungcap);
            nhaccbinding();
        }
        private void data_nhacc()
        {
            nhacc_vo = new Threelayer.VO.nhacungcapVO();
            nhacc_vo.DiaChi = box_diachi.Text;
            nhacc_vo.MaNcc = box_mancc.Text;
            nhacc_vo.SDT = Convert.ToInt32(Box_sdt.Text);
            nhacc_vo.Ten = box_ten.Text;
        }
        private void nhaccbinding()
        {
            box_diachi.DataBindings.Clear();
            box_diachi.DataBindings.Add("text", dataGridchitiet.DataSource, "diachi");
            box_mancc.DataBindings.Clear();
            box_mancc.DataBindings.Add("text", dataGridchitiet.DataSource, "mancc");
            Box_sdt.DataBindings.Clear();
            Box_sdt.DataBindings.Add("text", dataGridchitiet.DataSource, "sdt");
            box_ten.DataBindings.Clear();
            box_ten.DataBindings.Add("text", dataGridchitiet.DataSource, "ten");
        }

        private void bt_nhacc_them_Click(object sender, EventArgs e)
        {
            data_nhacc();
            nhacc_bus = new Threelayer.BUS.nhacungcapBUS();
            nhacc_bus.nhacungcap_them(nhacc_vo);
            nhacc_Load(sender, e);
        }

        private void bt_nhacc_sua_Click(object sender, EventArgs e)
        {
            data_nhacc();
            nhacc_bus = new Threelayer.BUS.nhacungcapBUS();
            nhacc_bus.nhacungcap_sua(nhacc_vo);
            nhacc_Load(sender, e);
        }

        private void bt_nhacc_xoa_Click(object sender, EventArgs e)
        {
            data_nhacc();
            nhacc_bus = new Threelayer.BUS.nhacungcapBUS();
            nhacc_bus.nhacungcap_xoa(box_nhacc_timkiem.Text);
            nhacc_Load(sender, e);
        }

        private void bt_nhacc_timkiem_Click(object sender, EventArgs e)
        {
            dt.Clear();
            cmd.Dispose();
            cmd.Parameters.Clear();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.StoredProcedure;
            conn.Open();
            cmd.CommandText = "nhacc_timkiem";
            cmd.Parameters.Add("@mancc", SqlDbType.NVarChar, 200).Value = box_nhacc_timkiem.Text;
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            cmd.ExecuteNonQuery();
            da.Fill(dt);
            dataGridchitiet.DataSource = dt;
            conn.Close();
        }
    }
}
